// ============================== 导入依赖 ============================== //

import CORE from '@login/CORE'

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 结构树 —————————————————————————————— //

  async getTest(treeParam = { page: 1, size: 10000 }, TIP = '查询测试结构树') {
    const tree = getMock()
    const time = randomNum()

    return new Promise((resolve) => {
      setTimeout(() => {
        CORE.logInfo(TIP, treeParam, { code: 100, data: tree }, time)
        resolve(tree)
      }, 1)
    })
  },
}

// ============================== 内部方法 ============================== //

/**
 * 获取随机数字
 */
const randomNum = () => parseInt(Math.random() * 1000, 10) + 100 // (100 - 1100)

/**
 * 下一个 ID
 */
let next = 0

/**
 * 获取模拟数据
 */
const getMock = () => {
  next++
  return Array.from('iii').map((_, i) => ({
    id: `id-${next + i}`,
    name: `序号-${next + i}`,
    children: Array.from('jjj').map((_, j) => ({
      id: `id-${next + i}-${next + j}`,
      name: `序号-${next + i}-${next + j}`,
      children: [],
    })),
  }))
}
